{% extends "base_generic.html" %}

{% block title %}
  {% if form.instance.pk %}Edit Author{% else %}Add Author{% endif %} - Local Library
{% endblock %}

{% block content %}
<div class="row justify-content-center">
  <div class="col-md-6">
    <div class="card">
      <div class="card-header">
        <h3 class="mb-0">
          <i class="bi bi-person"></i>
          {% if form.instance.pk %}
            Edit Author: {{ form.instance }}
          {% else %}
            Add New Author
          {% endif %}
        </h3>
      </div>
      <div class="card-body">
        <form method="post">
          {% csrf_token %}
          
          {% if form.non_field_errors %}
            <div class="alert alert-danger">
              {{ form.non_field_errors }}
            </div>
          {% endif %}
          
          <div class="row">
            <div class="col-md-6">
              <div class="mb-3">
                <label for="{{ form.first_name.id_for_label }}" class="form-label">First Name *</label>
                {{ form.first_name }}
                {% if form.first_name.errors %}
                  <div class="text-danger">{{ form.first_name.errors }}</div>
                {% endif %}
              </div>
            </div>
            <div class="col-md-6">
              <div class="mb-3">
                <label for="{{ form.last_name.id_for_label }}" class="form-label">Last Name *</label>
                {{ form.last_name }}
                {% if form.last_name.errors %}
                  <div class="text-danger">{{ form.last_name.errors }}</div>
                {% endif %}
              </div>
            </div>
          </div>
          
          <div class="row">
            <div class="col-md-6">
              <div class="mb-3">
                <label for="{{ form.date_of_birth.id_for_label }}" class="form-label">Date of Birth</label>
                {{ form.date_of_birth }}
                {% if form.date_of_birth.errors %}
                  <div class="text-danger">{{ form.date_of_birth.errors }}</div>
                {% endif %}
              </div>
            </div>
            <div class="col-md-6">
              <div class="mb-3">
                <label for="{{ form.date_of_death.id_for_label }}" class="form-label">Date of Death</label>
                {{ form.date_of_death }}
                {% if form.date_of_death.errors %}
                  <div class="text-danger">{{ form.date_of_death.errors }}</div>
                {% endif %}
              </div>
            </div>
          </div>
          
          <div class="d-flex justify-content-between">
            <a href="{% url 'authors' %}" class="btn btn-secondary">
              <i class="bi bi-arrow-left"></i> Cancel
            </a>
            <button type="submit" class="btn btn-primary">
              <i class="bi bi-save"></i>
              {% if form.instance.pk %}Update Author{% else %}Add Author{% endif %}
            </button>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
{% endblock %} 